package top.likeqc.leetcode.editor.cn;

import java.util.HashMap;
import java.util.Map;

/**
 * @see <a href="https://leetcode.cn/problems/count-nice-pairs-in-an-array">1814. 统计一个数组中好对子的数目</a>
 */
public class CountNicePairsInAnArray {
    public static void main(String[] args) {
        Solution solution = new CountNicePairsInAnArray().new Solution();

        System.out.println(solution.countNicePairs(new int[] {42, 11, 1, 97}));
        System.out.println(solution.countNicePairs(new int[] {13, 10, 35, 24, 76}));
    }
    // leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int countNicePairs(int[] nums) {

            final int MOD = 1000000007;
            int res = 0;
            Map<Integer, Integer> h = new HashMap<Integer, Integer>();
            for (int i : nums) {
                int temp = i, j = 0;
                while (temp > 0) {
                    j = j * 10 + temp % 10;
                    temp /= 10;
                }
                res = (res + h.getOrDefault(i - j, 0)) % MOD;
                h.put(i - j, h.getOrDefault(i - j, 0) + 1);
            }
            return res;
        }
    }
    // leetcode submit region end(Prohibit modification and deletion)

}
